home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / HardwareContext-mips.h,v < prev    next >
Text File  |  1989-10-24  |  3KB  |  131 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.10.24.13.08.35;  author grunwald;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @// This may look like C code, but it is really -*- C++ -*-
  26. // 
  27. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  28. //
  29. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  30. //
  31. #ifndef    HardwareContext_h
  32. #define    HardwareContext_h
  33. #pragma once
  34.  
  35. #include <stream.h>
  36. #include <assert.h>
  37. #include <AwesimeConfig.h>
  38.  
  39. extern const long MagicStackMarker;
  40.  
  41. typedef void (*voidFuncP)();
  42.  
  43. class CpuMultiplexor;
  44. class SingleCpuMux;
  45. class MultiCpuMux;
  46. class SimulationMultiplexor;
  47.  
  48. typedef long HardwareContextQuad;
  49.  
  50. class HardwareContext {
  51.     //
  52.     //    The following four fields are machine dependent & their order
  53.     //    should not be changed.
  54.     //
  55.     HardwareContextQuad sp;
  56.     HardwareContextQuad fp;
  57.  
  58.     void** stackBase;    // bottom of stack
  59.     void** stackEnd;    // maximum depth of stack? (actually, a MIN value)
  60.     unsigned stackMax;    // maximum depth of stack? (actually, a MIN value)
  61.     unsigned stackSize;    // stack size in units of void*
  62.     void **stackMallocAt;
  63.     long *stackCheck;    // point to MagicStackMarker to check for corruption
  64.     unsigned checkStackLimits;
  65.     
  66.     friend class Thread;
  67.     friend class CpuMultiplexor;
  68.     friend class SingleCpuMux;
  69.     friend class MultiCpuMux;
  70.     friend class SimulationMultiplexor;
  71.     
  72.     //
  73.     //    Accessed by friend classes only
  74.     //
  75.     void switchContext(HardwareContext *to);
  76.     void magicSwitchTo(HardwareContext *to);
  77.     void **getSp();
  78.     
  79.     void **mallocAt();
  80.     void buildReturnFrame(void * returnThis, voidFuncP returnAddress);
  81.     void stackOverflow();
  82.     
  83.     //
  84.     // never allocated by anything other than friend classes
  85.     //
  86.     HardwareContext(int checked, unsigned stackSize);
  87.     
  88. public:
  89.     HardwareContext();
  90.     
  91.     long maxStackDepth();
  92.     void checkStack(int overage = 0);
  93.     void classPrintOn(ostream& strm);
  94. };
  95.  
  96. inline
  97. HardwareContext::HardwareContext()
  98. {
  99.     int NotReached = 0;
  100.     assert( NotReached );
  101. }
  102.  
  103. inline ostream&
  104. operator<<(ostream& strm, HardwareContext& ob)
  105. {
  106.     ob.classPrintOn(strm);
  107.     return strm;
  108. }
  109.  
  110. inline void **
  111. HardwareContext::getSp()
  112. {
  113.     register int theStackPointer asm("sp");
  114.     return( (void **) theStackPointer );
  115. }
  116.  
  117. inline void
  118. HardwareContext::checkStack(int overage)
  119. {
  120.     unsigned depth = stackBase - getSp() + overage;
  121.     if (stackMax < depth) {
  122.     stackMax = depth;
  123.     }
  124.     if ( stackMax >= stackSize || *stackCheck != MagicStackMarker ) {
  125.     stackOverflow();
  126.     }
  127. }
  128.  
  129. #endif    HardwareContext_h
  130. @
  131.